package com.celeritymq.logging;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.LogManager;
import java.util.logging.Logger;

public class LoggerFactory {

	static {
		String loggingFile = System.getProperty("logFile", "config/logging.properties");
		FileInputStream fis = null;
		try {
			fis = new FileInputStream(new File(loggingFile));
		} catch (FileNotFoundException e) {
			throw new ExceptionInInitializerError("can not find file[" + loggingFile + "]");
		}
		try {
			LogManager.getLogManager().readConfiguration(fis);
		} catch (SecurityException e) {
			throw new ExceptionInInitializerError(e);
		} catch (IOException e) {
			throw new ExceptionInInitializerError(e);
		} finally {
			if (fis != null) {
				try {
					fis.close();
				} catch (IOException e) {
				}
			}
		}
	}

	public static Logger getLogger(@SuppressWarnings("rawtypes") Class clz) {
		return Logger.getLogger(clz.getName());
	}

}
